﻿namespace _9jCardRegisterCollection.Helper
{
    public class CheckUserInputHelper
    {
        /// <summary>
        /// 验证身份证号是否合法
        /// </summary>
        /// <param name="IDNumber">身份证号</param>
        /// <returns></returns>
        public static string CheckInputIDNumber(string IDNumber)
        {
            if (IDNumber.Length != 18) return "身份证号必须为18位；";

            if (IDNumber.Substring(14, 4) == "0000") return "身份证号后4位不能为0000；";

            return string.Empty;
        }

        /// <summary>
        /// 获取身份证号中的性别
        /// </summary>
        /// <param name="IDNumber">身份证号</param>
        /// <returns></returns>
        public static string GetIDNumberGender(string IDNumber)
        {
            var gender = IDNumber.Substring(14, 3);

            if (int.Parse(gender) % 2 != 0)
            {
                return "男";
            }
            return "女";
        }

        /// <summary>
        /// 验证境外姓名输入是否正确
        /// </summary>
        /// <param name="idTypeCode">国家代码</param>
        /// <param name="fullName">姓名</param>
        /// <param name="lastName">英文姓</param>
        /// <param name="firstName">英文名</param>
        /// <returns></returns>
        public static string CheckInputName(string idTypeCode, string fullName, string lastName, string firstName)
        {
            // 当证件类型为“港澳台通行证，台胞证”时必填
            if (idTypeCode == "2" || idTypeCode == "3")
            {

                if (string.IsNullOrWhiteSpace(fullName))
                {
                    return "中文姓名必填";
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(lastName) || string.IsNullOrWhiteSpace(firstName))
                {
                    return "英文姓，英文名或姓名必填一个";
                }
            }
            return "";
        }
    }
}
